package com.itany.shop.service.Impl;

import com.itany.shop.constant.DictConstant;
import com.itany.shop.dao.ProductDao;
import com.itany.shop.entity.Product;
import com.itany.shop.exception.ProductNotExistException;
import com.itany.shop.factory.ObjectFactory;
import com.itany.shop.service.ProductService;
import com.itany.shop.util.ParameterUtil;

import java.util.List;

/**
 * @author 黄衡熙
 * @version 1.0
 */
public class ProductServiceImpl implements ProductService {
    private ProductDao productDao=(ProductDao) ObjectFactory.getObject("productDao");
    @Override
    public List<Product> findAll() {
        return productDao.selectAll();
    }
    @Override
    public List<Product> findPage(String pageNo, String pageSize) throws ProductNotExistException {
        if (ParameterUtil.isNull(pageNo)) {
            pageNo = DictConstant.PRODUCT_DEFAULT_PAGE_NO;
        }
        if (ParameterUtil.isNull(pageSize)) {
            pageSize = DictConstant.PRODUCT_DEFAULT_PAGE_SIZE;
        }
        List<Product> products = productDao.selectPage(Integer.parseInt(pageNo), Integer.parseInt(pageSize));
        if (products.isEmpty()) {
            throw new ProductNotExistException("超出了页码范围");
        }
        return products;
    }
}
